package com.github.binarywang.demo.wechat.controller;

import com.github.binarywang.demo.wechat.model.Favorite;
import com.github.binarywang.demo.wechat.model.FavoriteKey;
import com.github.binarywang.demo.wechat.service.WxFavoriteService;
import com.github.binarywang.demo.wechat.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({ "wechat/favorite" })
@RestController
public class WxFavoriteController {
	@Autowired
	private WxFavoriteService wxFavoriteService;

	@GetMapping({ "insert" })
	public int insert(Favorite favorite) {
		return this.wxFavoriteService.insert(favorite);
	}

	@GetMapping({ "findByCourseId" })
	public String list(Integer courseId, Integer start) {
		return JsonUtils.toJson(this.wxFavoriteService.findByCourseId(courseId, start));
	}

	@GetMapping({ "findByOpenId" })
	public String list(String openId, Integer start) {
		return JsonUtils.toJson(this.wxFavoriteService.findByOpenId(openId, start));
	}

	@GetMapping({ "delete" })
	public int delete(FavoriteKey favoriteKey) {
		return this.wxFavoriteService.delete(favoriteKey);
	}
}
